package com.medical.common.web.controller;

import com.medical.common.Constant;
import com.medical.sys.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by JUNZI on 2015/8/16.
 */
public abstract class BaseController {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    protected User getCurrentUser(HttpServletRequest req){
        if(req.getAttribute(Constant.CURRENT_USER) != null){
            return (User)req.getAttribute(Constant.CURRENT_USER);
        }
        return null;
    }

    protected String getCurrentUsername(HttpServletRequest req){
        User user = getCurrentUser(req);
        if(user != null){
            return user.getUsername();
        }
        return "";
    }
}
